package com.health.fragment.focusgroup.wb;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.ARCHIVE_GENERALCONDITION;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CD_DRUGCONDITION;
import com.health.tablebean.CD_HYPERTENSIONFOLLOWUP;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.PersonalFileActivity.onFragmentSave;
import com.health.viewscontrols.focusgroup.GXYActivity;
import com.health.widget.EditTextWithDate2;
import com.health.widget.MyGridView;
import com.novabluetooth.services.BluetoothConstant;
import com.novabluetooth.views.ExamHistoryActivity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 重点人群-- 高血压--随访
 * 
 * @author nova
 *
 */
public class GXY_SfFragment1 extends NovaFragment implements onFragmentSave, OnClickListener {
	private static final String TAG = "GXY_SfFragment";
	private View cqsf2View = null;
	private FDbManager fdbmanger = null;

	// ------------------------------基本信息-----------------------------
	private EditTextWithDate2 ed_date;
	private NiceSpinner ed_sfys;// 随访医生
	private NiceSpinner nice_spinner_szfs;// 选择随诊方式

	private MyGridView gd_zz;// 症状

	private EditText ed_xy;// 血压
	private Button btn_choose_xy;

	private EditText ed_xl;// 心率
	private EditText ed_tz;// 体重
	private Button btn_choose_tz;// 选择体重
	private EditText ed_xcsfmb_tz;// 下次随访目标 体重
	private Button btn_choose_xl;
	
	
	private EditText ed_tzzs;// 体质指数
	private EditText ed_height;// 身高
	private EditText ed_tzzs_sf;// 体质指数 随访
	private EditText ed_qt;// 其他
	private EditText ed_rxyl;// 日吸烟量
	private EditText ed_xcsfmb_xy;// 日吸烟量 随访
	private EditText ed_ryjl;// 日饮酒量

	private EditText ed_xcsfmb_yj;// 日饮酒量 随访
	private EditText ed_yd_zq;// 运动周
	private EditText ed_yd_min;// 运动分钟
	private EditText ed_xcsfmb_yd_zq;// 运动周
	private EditText ed_xcsfmb_yd_min;// 运动分钟
	private NiceSpinner nice_spinner_syqk;// 摄盐情况
	private EditText syqk_edt;//每日摄盐情况
	private NiceSpinner nice_spinner_xcsfmb;// 摄盐情况
	private NiceSpinner nice_spinner_xltz;// 摄盐情况
	private NiceSpinner nice_spinner_zyxw;// 遵医行为

	private EditText ed_fzjc;// 辅助检查
	private NiceSpinner nice_spinner_fyycx;// 服药依从性
	private MyGridView gd_ywblfy;// 药物不良反应

	private NiceSpinner nice_spinner_clsffl;// 此类随访分类
	private AutoCompleteTextView ed_ywmc1;// 药物名称1
	private NiceSpinner nice_spinner_dw1;// 药物单位1
	private NiceSpinner nice_spinner_dw2;// 药物单位2
	private NiceSpinner nice_spinner_dw3;// 药物单位3
	private NiceSpinner nice_spinner_dwqt;// 药物单位其他
	private EditText ed_ywmc1_day;// 每日 day
	private EditText ed_ywmc1_mg;// 每次 mg

	private AutoCompleteTextView ed_ywmc2;// 药物名称2

	private EditText ed_ywmc2_day;// 每日 day
	private EditText ed_ywmc2_mg;// 每次 mg
	private AutoCompleteTextView ed_ywmc3;// 药物名称3

	private EditText ed_ywmc3_day;// 每日 day
	private EditText ed_ywmc3_mg;// 每次 mg

	private AutoCompleteTextView ed_qtyw;// 药物名称3

	private EditText ed_qtyw_day;// 每日 day
	private EditText ed_qtyw_mg;// 每次 mg
	private EditText ed_zzyy;// 转诊原因
	private EditText ed_jgkb;// 机构及科别
	private EditTextWithDate2 ed_xcsfsj;// 下次随访时间

	private RadioGroup zhuanzhen_group;//是否转诊
	private RadioButton zhuanzhen_no;
	private RadioButton zhuanzhen_yes;
	private LinearLayout zhuanzhen_layout;
	String isREFERRAL="DM01-11_1";//是否转诊
	EditText jiankangjianyi;//健康评价

	// ----------------------------------------------------------------------
	private RadioButtonAdapter adapter_ywblfy = null;

	private CheckBoxAdapter adapter_zz = null;

	private List<BD_DD_INFO> sy_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> xcsfmb_list = new ArrayList<BD_DD_INFO>();

	private List<BD_DD_INFO> xltz_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> zyxw_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> ywycx_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> szfs_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> ccsffl_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> ywdw_list = new ArrayList<BD_DD_INFO>();
	public ARCHIVE_BASEINFO userInfo;
	private CD_HYPERTENSIONFOLLOWUP followUp;

	//todo
	String strWhere = "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "'";
	private CD_HYPERTENSIONFOLLOWUP readFollowup;
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	// 定义字符串数组，作为提示的文本
	String[] gxy_yws = new String[] { "缬沙坦片", "复方利血平片", "复方利血平氨苯蝶啶片", "硝苯地平缓释片", "硝苯地平控释片", "卡托普利片", "尼莫地平片",
			"马来酸依那普利片", "苯磺酸氨氯地平片", "吲达帕胺片", "依那普利片", "心普利片", "心胺利片", "硝苯地平片", "尼群地平片", };
	List<ARCHIVE_GENERALCONDITION> ags;
    private String gaoya = "0";
    private String diya = "0";
	private NiceSpinner nice_spinner_cc1;
	private NiceSpinner nice_spinner_cc2;
	private NiceSpinner nice_spinner_cc3;
	private NiceSpinner nice_spinner_cc4;
	private List<String> ccList;
	private NiceSpinner nice_spinner_yl1;
	private NiceSpinner nice_spinner_yl2;
	private NiceSpinner nice_spinner_yl3;
	private NiceSpinner nice_spinner_yl4;

	@Override
	public View findViews(LayoutInflater inflater) {
		fdbmanger = NovaApplication.fdbmanger;
		userInfo = NovaApplication.getUserInfo();
		ags = fdbmanger.findAllByWhere(ARCHIVE_GENERALCONDITION.class, "IDCARD = '" + userInfo.getIDCARD() + "'");
		cqsf2View = inflater.inflate(R.layout.gxy_sfxx, null);
		initViews(cqsf2View);
		GlobalConts.setMaxLength(13, ed_xy);// 血压
		GlobalConts.setMaxLength(3, ed_xl, ed_rxyl, ed_xcsfmb_xy, ed_ryjl, ed_xcsfmb_yj, ed_yd_zq, ed_yd_min,
				ed_xcsfmb_yd_zq, ed_xcsfmb_yd_min);// 心率
		GlobalConts.setMaxLength(50, ed_qt, ed_fzjc, ed_zzyy, ed_jgkb);// 其他
		GlobalConts.setMaxLength(35, ed_ywmc1, // 药物名称1
				ed_ywmc2, // 药物名称2
				ed_ywmc3, // 药物名称3
				ed_qtyw);// 药物名称3
		return cqsf2View;
	}

	/**
	 * 初始化布局
	 * 
	 * @param v
	 * @author 王婷婷
	 * @date 2015年12月21日 上午11:10:55
	 */
	private void initViews(View v) {
		ed_date = (EditTextWithDate2) v.findViewById(R.id.ed_date);
		ed_sfys = (NiceSpinner) v.findViewById(R.id.ed_sfys);
		nice_spinner_szfs = (NiceSpinner) v.findViewById(R.id.nice_spinner_szfs);

		gd_zz = (MyGridView) v.findViewById(R.id.gd_zz);

		ed_xy = (EditText) v.findViewById(R.id.ed_xy);
		btn_choose_xy = (Button) v.findViewById(R.id.btn_choose_xy);
		btn_choose_xl=(Button)v.findViewById(R.id.btn_choose_xl);
		
		ed_xl = (EditText) v.findViewById(R.id.ed_xl);
		ed_tz = (EditText) v.findViewById(R.id.ed_tz);
		btn_choose_tz = (Button) v.findViewById(R.id.btn_choose_tz);
		ed_xcsfmb_tz = (EditText) v.findViewById(R.id.ed_xcsfmb_tz);

		ed_tzzs = (EditText) v.findViewById(R.id.ed_tzzs);
		ed_height = (EditText) v.findViewById(R.id.ed_height);
		ed_tzzs_sf = (EditText) v.findViewById(R.id.ed_tzzs_sf);
		ed_qt = (EditText) v.findViewById(R.id.ed_qt);
		ed_rxyl = (EditText) v.findViewById(R.id.ed_rxyl);
		ed_xcsfmb_xy = (EditText) v.findViewById(R.id.ed_xcsfmb_xy);
		ed_ryjl = (EditText) v.findViewById(R.id.ed_ryjl);

		ed_xcsfmb_yj = (EditText) v.findViewById(R.id.ed_xcsfmb_yj);
		syqk_edt=v.findViewById(R.id.syqk_edt);
		ed_yd_zq = (EditText) v.findViewById(R.id.ed_yd_zq);
		ed_yd_min = (EditText) v.findViewById(R.id.ed_yd_min);
		ed_xcsfmb_yd_zq = (EditText) v.findViewById(R.id.ed_xcsfmb_yd_zq);
		ed_xcsfmb_yd_min = (EditText) v.findViewById(R.id.ed_xcsfmb_yd_min);
		nice_spinner_syqk = (NiceSpinner) v.findViewById(R.id.nice_spinner_syqk);
		nice_spinner_xcsfmb = (NiceSpinner) v.findViewById(R.id.nice_spinner_xcsfmb);
		nice_spinner_xltz = (NiceSpinner) v.findViewById(R.id.nice_spinner_xltz);
		nice_spinner_zyxw = (NiceSpinner) v.findViewById(R.id.nice_spinner_zyxw);

		ed_fzjc = (EditText) v.findViewById(R.id.ed_fzjc);
		nice_spinner_fyycx = (NiceSpinner) v.findViewById(R.id.nice_spinner_fyycx);
		gd_ywblfy = (MyGridView) v.findViewById(R.id.gd_ywblfy);

		nice_spinner_clsffl = (NiceSpinner) v.findViewById(R.id.nice_spinner_clsffl);
		ed_ywmc1 = (AutoCompleteTextView) v.findViewById(R.id.ed_ywmc1);

		ed_ywmc1_day = (EditText) v.findViewById(R.id.ed_ywmc1_day);
		ed_ywmc1_mg = (EditText) v.findViewById(R.id.ed_ywmc1_mg);

		ed_ywmc2 = (AutoCompleteTextView) v.findViewById(R.id.ed_ywmc2);
		ed_ywmc2_day = (EditText) v.findViewById(R.id.ed_ywmc2_day);
		ed_ywmc2_mg = (EditText) v.findViewById(R.id.ed_ywmc2_mg);
		ed_ywmc3 = (AutoCompleteTextView) v.findViewById(R.id.ed_ywmc3);
		ed_ywmc3_day = (EditText) v.findViewById(R.id.ed_ywmc3_day);
		ed_ywmc3_mg = (EditText) v.findViewById(R.id.ed_ywmc3_mg);

		ed_qtyw = (AutoCompleteTextView) v.findViewById(R.id.ed_qtyw);
		ed_qtyw_day = (EditText) v.findViewById(R.id.ed_qtyw_day);
		ed_qtyw_mg = (EditText) v.findViewById(R.id.ed_qtyw_mg);
		ed_zzyy = (EditText) v.findViewById(R.id.ed_zzyy);
		ed_jgkb = (EditText) v.findViewById(R.id.ed_jgkb);
		ed_xcsfsj = (EditTextWithDate2) v.findViewById(R.id.ed_xcsfsj);
		nice_spinner_dw1 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw1);
		nice_spinner_dw2 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw2);
		nice_spinner_dw3 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw3);
		nice_spinner_dwqt = (NiceSpinner) v.findViewById(R.id.nice_spinner_dwqt);

//		nice_spinner_cc1 = (NiceSpinner) v.findViewById(R.id.nice_spinner_cc1);
//		nice_spinner_cc2 = (NiceSpinner) v.findViewById(R.id.nice_spinner_cc2);
//		nice_spinner_cc3 = (NiceSpinner) v.findViewById(R.id.nice_spinner_cc3);
//		nice_spinner_cc4 = (NiceSpinner) v.findViewById(R.id.nice_spinner_cc4);
//
//		nice_spinner_yl1 = (NiceSpinner) v.findViewById(R.id.nice_spinner_yl1);
//		nice_spinner_yl2 = (NiceSpinner) v.findViewById(R.id.nice_spinner_yl2);
//		nice_spinner_yl3 = (NiceSpinner) v.findViewById(R.id.nice_spinner_yl3);
//		nice_spinner_yl4 = (NiceSpinner) v.findViewById(R.id.nice_spinner_yl4);

		ed_date.setBefore(true);
		String threeTime = getThreeTime();
		ed_xcsfsj.setText(threeTime);
		ed_xcsfsj.setAfter(true,0);
		zhuanzhen_group=v.findViewById(R.id.zhuanzhen_group);
		zhuanzhen_no=v.findViewById(R.id.zhuanzhen_no);
		zhuanzhen_yes=v.findViewById(R.id.zhuanzhen_yes);
		zhuanzhen_layout=v.findViewById(R.id.zhuanzhen_layout);
		jiankangjianyi=v.findViewById(R.id.jiankangjianyi);

		// 创建一个ArrayAdapter，封装数组
		ArrayAdapter<String> arr = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line,
				gxy_yws);

		ed_ywmc1.setAdapter(arr);
		ed_ywmc2.setAdapter(arr);
		ed_ywmc3.setAdapter(arr);
		ed_qtyw.setAdapter(arr);

	}

	/**
	 * 绑定数据值
	 * 
	 * @param str_where
	 * @param flag
	 * @author 王婷婷
	 * @date 2015年12月17日 上午10:30:30
	 */
	private void bindDdata(String flag, String str_where) {
		List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, str_where);
		if (flag.equals("症状")) {
			int size = listZZs.size();
			List<BD_DD_INFO> bd_zzs;
			if (size > 0) {
				bd_zzs = new ArrayList<BD_DD_INFO>();
				for (int i = 0; i < size; i++) {
					String str_id = listZZs.get(i).getID();
					if (str_id.equals("DM04-02_R42.x") || str_id.equals("DM04-02_H93.1")) {

					} else {
						bd_zzs.add(listZZs.get(i));
					}
				}
				adapter_zz = new CheckBoxAdapter(getActivity(), bd_zzs);

			}
			gd_zz.setAdapter(adapter_zz);
		} else if (flag.equals("药物不良反应")) {
			adapter_ywblfy = new RadioButtonAdapter(listZZs, getActivity());
			adapter_ywblfy.setOtherMaxLength(50);
			gd_ywblfy.setAdapter(adapter_ywblfy);
		}

	}

	/**
	 * 设置下拉
	 * 
	 * @param flagName
	 * @param strSql
	 * @author 王婷婷
	 * @date 2015年12月24日 上午9:19:28
	 */

	private void bindSpinner(String flagName, String strSql) {
		List<BD_DD_INFO> sList = new ArrayList<BD_DD_INFO>();
		BD_DD_INFO bd = new BD_DD_INFO();
		bd.setDATAINFO("请选择");
		bd.setID("");
		sList.add(bd);

		List<BD_DD_INFO> sList1 = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				strSql + " order by cast(SORT as int) asc");
		sList.addAll(sList1);
		if (flagName.equals("摄盐")) {
			sy_list = sList;
			nice_spinner_syqk.attachDataSource(sy_list);

		} else if (flagName.equals("下次随访目标")) {
			xcsfmb_list = sList;
			nice_spinner_xcsfmb.attachDataSource(xcsfmb_list);

		} else if (flagName.equals("心理情况")) {

			int size = sList.size();
			if (size > 0) {
				xltz_list = new ArrayList<BD_DD_INFO>();
				zyxw_list = new ArrayList<BD_DD_INFO>();
				for (int i = 0; i < size; i++) {
					String str_id = sList.get(i).getID();
					if (str_id.equals("DM01-69_1") || str_id.equals("DM01-69_2") || str_id.equals("DM01-69_3")
							|| str_id.equals("")) {
						xltz_list.add(sList.get(i));
						zyxw_list.add(sList.get(i));
					}
				}
			}

			nice_spinner_xltz.attachDataSource(xltz_list);
			nice_spinner_zyxw.attachDataSource(zyxw_list);
		} else if (flagName.equals("药物依从性")) {
			ywycx_list = sList;
			nice_spinner_fyycx.attachDataSource(ywycx_list);
		} else if (flagName.equals("此次随访分类")) {
			int size = sList.size();
			if (size > 0) {
				ccsffl_list = new ArrayList<BD_DD_INFO>();
				for (int i = 0; i < size; i++) {
					String str_id = sList.get(i).getID();
					if (str_id.equals("DM01-71_1") || str_id.equals("DM01-71_2") || str_id.equals("DM01-71_3")
							|| str_id.equals("DM01-71_4") || str_id.equals("")) {
						ccsffl_list.add(sList.get(i));
					}
				}
			}

			nice_spinner_clsffl.attachDataSource(ccsffl_list);
		} else if (flagName.equals("随诊方式")) {
			szfs_list = sList;
			nice_spinner_szfs.attachDataSource(szfs_list);
		} else if (flagName.equals("药物单位")) {
			ywdw_list = sList1;
			nice_spinner_dw1.attachDataSource(sList1);
			nice_spinner_dw2.attachDataSource(sList1);
			nice_spinner_dw3.attachDataSource(sList1);
			nice_spinner_dwqt.attachDataSource(sList1);
		}

	}

	@Override
	public void setupView(View view) {

	}

	@Override
	public void addListener() {
		btn_choose_xy.setOnClickListener(this);
		btn_choose_tz.setOnClickListener(this);
		btn_choose_xl.setOnClickListener(this);
		changeBMI(ed_height, ed_tz, ed_tzzs);
		changeBMI(ed_height, ed_xcsfmb_tz, ed_tzzs_sf);
		zhuanzhen_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if(checkedId==zhuanzhen_no.getId()){
					zhuanzhen_layout.setVisibility(View.GONE);
					isREFERRAL="DM01-11_1";
					ed_zzyy.setText("");
					ed_jgkb.setText("");
				}else if(checkedId==zhuanzhen_yes.getId()){
					isREFERRAL="DM01-11_2";
					zhuanzhen_layout.setVisibility(View.VISIBLE);
				}
			}
		});
	}

	/**
	 * 身高或者体重改变时，BMI的值随之发生改变
	 **/
	private void changeBMI(final EditText etHeight, final EditText etWeight, final EditText etBMI) {
		etHeight.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				if (!TextUtils.isEmpty(etWeight.getText().toString())) {
					setBMI(etHeight, etWeight, etBMI);
				}else{
					etBMI.setText("");
				}
				
				if (TextUtils.isEmpty(s.toString())) {
					etBMI.setText("");
				}

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			@Override
			public void afterTextChanged(Editable s) {

			}
		});

		etWeight.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				if (!TextUtils.isEmpty(etHeight.getText().toString())) {
					setBMI(etHeight, etWeight, etBMI);
				}else{
					etBMI.setText("");
				}
				if (TextUtils.isEmpty(s.toString())) {
					etBMI.setText("");
				}
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable s) {

			}
		});
	}

	/**
	 * 设置BMI
	 * 
	 * @author 王婷婷
	 * @date 2017年4月5日 上午10:48:51
	 */
	private void setBMI(EditText etHeight, EditText etWeight, EditText etBMI) {
		try {
			if (TextUtils.isEmpty(etHeight.getText().toString()) || TextUtils.isEmpty(etHeight.getText().toString())) {
				etBMI.setText("");
				return;
			}

			double dh = Double.parseDouble(etHeight.getText().toString()) / 100;
			double dw = Double.parseDouble(etWeight.getText().toString());

			java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");

			etBMI.setText(df.format(GlobalConts.getBMI(dh, dw)) + "");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}


	@Override
	public void setData() {
		try {

			// TODO
			bindDdata("症状", "PARENTID='DM04-02'");
			bindDdata("药物不良反应", "PARENTID='DM01-11'");

			bindSpinner("摄盐", "PARENTID='DM01-68'");
			bindSpinner("下次随访目标", "PARENTID='DM01-68'");
			bindSpinner("心理情况", "PARENTID='DM01-69'");
			bindSpinner("药物依从性", "PARENTID='DM01-70'");
			bindSpinner("此次随访分类", "PARENTID='DM01-71'");
			bindSpinner("随诊方式", "PARENTID='DM04-15'");
			bindSpinner("药物单位", "PARENTID='DM04-05'");
			GlobalConts.doctorList(ed_sfys);
			setDBData();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private int fromCD_HY = 0;
	private int fromCD_DR = 0;

	private void setDBData() {
		List<CD_HYPERTENSIONFOLLOWUP> list = fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, strWhere);

		ccList = new ArrayList<String>();
		ccList.add("口服");
		ccList.add("直肠用药");
		ccList.add("舌下用药");
		ccList.add("注射用药");
		ccList.add("吸入用药");
		ccList.add("局部用药");

		ccList.add("皮下注射");
		ccList.add("皮内注射");
		ccList.add("其它途径");
		ccList.add("滴眼");
		ccList.add("喷喉");
		ccList.add("滴鼻");
		ccList.add("含化");
		ccList.add("敷伤口");
		ccList.add("擦皮肤");
		ccList.add("胸膜腔用药");
		ccList.add("腹腔用药");
		ccList.add("阴道用药");
		ccList.add("推管内用药");
		ccList.add("气管内用药");

		ccList.add("关节腔内用药");
		ccList.add("肌肉注射");
		ccList.add("静脉注射或静脉滴注");
		ccList.add("其他局部用药");

		nice_spinner_cc1.attachDataSource(ccList);
		nice_spinner_cc2.attachDataSource(ccList);
		nice_spinner_cc3.attachDataSource(ccList);
		nice_spinner_cc4.attachDataSource(ccList);

		List<String> ylList = new ArrayList<String>();
		ylList.add("一日两次");
		ylList.add("一周两次");
		ylList.add("睡前服用");
		ylList.add("12小时一次");
		ylList.add("1小时一次");
		ylList.add("3小时一次");
		ylList.add("6小时一次");
		ylList.add("一日三次");
		ylList.add("一日一次");
		ylList.add("一日四次");
		ylList.add("隔日一次");
		ylList.add("一周一次");
		ylList.add("一周两次");
		ylList.add("立即服用");
		ylList.add("其他");
		nice_spinner_yl1.attachDataSource(ylList);
		nice_spinner_yl2.attachDataSource(ylList);
		nice_spinner_yl3.attachDataSource(ylList);
		nice_spinner_yl4.attachDataSource(ylList);

		Log.e(TAG,"查询大小："+list.size());
		if (list.size() > 0) {
			fromCD_HY = 1;
			readFollowup = list.get(0);
			ed_date.setDate(readFollowup.getFOLLOWUPDATE());
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (NovaApplication.getDoctorList().get(i).getUSER_ID().equals(readFollowup.getFOLLOWUPDOCTOR())) {
					ed_sfys.setSelectedIndex(i);
				}

			}
			String symptoms = readFollowup.getSYMPTOM();
			adapter_zz.setChecked(symptoms);
			adapter_zz.setOther(readFollowup.getSYMPTOMOTHER());
			if (readFollowup.getFOLLOWUPWAY().contains("DM04-04")){
				nice_spinner_szfs.setSelectedIndex(getListIndex(readFollowup.getFOLLOWUPWAY().replace("DM04-04","DM04-15"), szfs_list));
			}else{
				nice_spinner_szfs.setSelectedIndex(getListIndex(readFollowup.getFOLLOWUPWAY(), szfs_list));
			}


			if (!TextUtils.isEmpty(readFollowup.getHYPERTENSION())) {
				if ((!TextUtils.isEmpty(readFollowup.getHYPERTENSION()))
						&& (!TextUtils.isEmpty(readFollowup.getHYPOTENSION()))) {
				}
				ed_xy.setText(notNull(readFollowup.getHYPERTENSION() + "/" + readFollowup.getHYPOTENSION()));
			}
			ed_xl.setText(notNull(readFollowup.getHEARTRATE()));
			ed_tz.setText(notNull(readFollowup.getWEIGHT()));
			ed_xcsfmb_tz.setText(notNull(readFollowup.getWEIGHTTARGET()));
			ed_tzzs.setText(notNull(readFollowup.getBMI()));
			ed_height.setText(notNull(readFollowup.getHeight()));
			ed_tzzs_sf.setText(notNull(readFollowup.getBMITARGET()));
			ed_qt.setText(notNull(readFollowup.getPHYSICALSYMPTOMOTHER()));
			if(!TextUtils.isEmpty(readFollowup.getISREFERRAL())){
				if("DM01-11_1".equals(readFollowup.getISREFERRAL())){
					zhuanzhen_no.setChecked(true);
					zhuanzhen_yes.setChecked(false);
					zhuanzhen_layout.setVisibility(View.GONE);
				}else if("DM01-11_2".equals(readFollowup.getISREFERRAL())){
					zhuanzhen_yes.setChecked(true);
					zhuanzhen_no.setChecked(false);
					zhuanzhen_layout.setVisibility(View.VISIBLE);
				}
			}
			jiankangjianyi.setText(notNull(readFollowup.getHEALTH_ASSESS()));

			ed_rxyl.setText(notNull(readFollowup.getDAILYSMOKENUM()));
			ed_xcsfmb_xy.setText(notNull(readFollowup.getDAILYSMOKENUMTARGET()));
			ed_ryjl.setText(notNull(readFollowup.getDAILYDRINKNUM()));
			ed_xcsfmb_yj.setText(notNull(readFollowup.getDAILYDRINKNUMTARGET()));
			syqk_edt.setText(notNull(readFollowup.getTOSALT()));
			ed_yd_zq.setText(notNull(readFollowup.getSPORTTIMEPERWEEK()));
			ed_yd_min.setText(notNull(readFollowup.getSPORTPERMINUTETIME()));
			ed_xcsfmb_yd_zq.setText(notNull(readFollowup.getSPORTTIMESPERWEEKTARGET()));
			ed_xcsfmb_yd_min.setText(notNull(readFollowup.getSPORTPERMINUTESTIMETARGET()));
			ed_fzjc.setText(readFollowup.getASSISTANTEXAM());
			System.out.println(readFollowup.getEATSALTTYPE() + "************");
			nice_spinner_syqk.setSelectedIndex(getListIndex(readFollowup.getEATSALTTYPE(), sy_list));
			nice_spinner_xcsfmb.setSelectedIndex(getListIndex(readFollowup.getEATSALTTARGET(), xcsfmb_list));
			nice_spinner_xltz.setSelectedIndex(getListIndex(readFollowup.getPSYCHOADJUSTMENT(), xltz_list));
			nice_spinner_zyxw.setSelectedIndex(getListIndex(readFollowup.getOBEYDOCTORBEHAVIOR(), zyxw_list));
			nice_spinner_clsffl.setSelectedIndex(getListIndex(readFollowup.getFOLLOWUPTYPE(), ccsffl_list));
			nice_spinner_fyycx.setSelectedIndex(getListIndex(readFollowup.getMEDICATIONCOMPLIANCE(), ywycx_list));
			adapter_ywblfy.setChecked(readFollowup.getADR());
			adapter_ywblfy.setChecked(adapter_ywblfy.getChecked(), readFollowup.getADR_EX());
			ed_zzyy.setText(readFollowup.getREFERRALREASON());
			ed_jgkb.setText(readFollowup.getREFERRALORG());

			if (readFollowup.getNEXTFOLLOWUPDATE() != null) {
				try {
					ed_xcsfsj.setText(dateFormat.format(readFollowup.getNEXTFOLLOWUPDATE()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		} else {
			ed_date.setText(dateFormat.format(new Date()));
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
					ed_sfys.setSelectedIndex(i);
				}
			}
		}
		// drugCondition1.setTYPE("1");
		// if (!TextUtils.isEmpty(medicine1)) {
		// drugCondition1.setNAME(medicine1);
		// drugCondition1.setDAILYTIME(getInt(count1));
		// drugCondition1.setEVERYTIMEMG(getInt(dose1));
		// fdbmanger.save(drugCondition1);
		// }
		List<CD_DRUGCONDITION> drugList = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class, strWhere + "AND TYPE = '1'");
		if (drugList.size() > 0) {
			fromCD_DR = 1;
			int size = drugList.size();
			EditText[] medicals = { ed_ywmc1, ed_ywmc2, ed_ywmc3, ed_qtyw };
//			EditText[] times = { ed_ywmc1_day, ed_ywmc2_day, ed_ywmc3_day, ed_qtyw_day };
			EditText[] doses = { ed_ywmc1_mg, ed_ywmc2_mg, ed_ywmc3_mg, ed_qtyw_mg };
            NiceSpinner[] times = {nice_spinner_cc1,nice_spinner_cc2,nice_spinner_cc3,nice_spinner_cc4};
            NiceSpinner[] times2 = {nice_spinner_yl1,nice_spinner_yl2,nice_spinner_yl3,nice_spinner_yl4};

            for (int i = 0; i < size; i++) {
				CD_DRUGCONDITION drug = drugList.get(i);
				medicals[i].setText(notNull(drug.getNAME()));
                String dailytime = drug.getDAILYTIME();
                if(null != dailytime && !dailytime.equals("")){
                    if(dailytime.contains("/")){
                        String[] split = dailytime.split("/");
                        if(null != split && !split.equals("")){
                            String s = split[1];
                            if(null != s && !s.equals("")){
                                if(s.equals("99")){
                                    times[i].setSelectedIndex(23);
                                }else{
									times[i].setSelectedIndex(Integer.parseInt(s)-1);
                                }
                            }
                            String s1 = split[0];
                            if(null != s1 && !s1.equals("")){
                                if(s1.equals("99")){
                                    times2[i].setSelectedIndex(14);
                                }else{
                                    times2[i].setSelectedIndex(Integer.parseInt(s1)-1);
                                }
                            }
                        }
                    }
                }
//                times[i].setText(notNull(drug.getDAILYTIME()));
				doses[i].setText(notNull(String.valueOf(drug.getEVERYTIMEMG())));
				if (i == 0) {
					nice_spinner_dw1.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
				} else if (i == 1) {
					nice_spinner_dw2.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
				} else if (i == 2) {
					nice_spinner_dw3.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
				} else if (i == 3) {
					nice_spinner_dwqt.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
				}
			}
		}
	}


	protected String getThreeTime() {
		int mYear;
		int mMonth;
		int mDay;
		String fmt = null;
		final Calendar c = Calendar.getInstance();
		mYear = c.get(Calendar.YEAR);
		mMonth = c.get(Calendar.MONTH) + 4;

		String monStr = mMonth + "";
		if (monStr.length() == 1) {
			monStr = "0" + monStr;
		}

		mDay = c.get(Calendar.DAY_OF_MONTH);
		String dayStr = mDay + "";
		if (dayStr.length() == 1) {
			dayStr = "0" + dayStr;
		}

		fmt = "" + mYear + "-" + monStr + "-" + dayStr;
		return fmt;
	}

	private int getListIndex(String str, List<BD_DD_INFO> bds) {
		if (str != null && !str.equals("")) {

			for (int i = 0; i < bds.size(); i++) {
				if (str.equals(bds.get(i).getID())) {
					return i;
				}
			}
		}
		return 0;
	}

	private String notNull(String str) {
		if (TextUtils.isEmpty(str)) {
			return "";
		}
		return str;
	}

	public void save() {
		// 随诊方式
		Log.e(TAG,"用量内容："+nice_spinner_yl1.getText()+"--"+nice_spinner_yl1.getSelectedIndex());
		String str_id = szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID();
		Log.w(TAG, "随诊方式：" + str_id);
		if (TextUtils.isEmpty(str_id)) {
			nice_spinner_szfs.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请选择随诊方式");
			return;
		} else {
			nice_spinner_szfs.setBackgroundColor(Color.WHITE);
		}

		// 症状
		String str_zz = adapter_zz.getCheckedIdsStr();
		if (TextUtils.isEmpty(str_zz)) {
			gd_zz.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请选择症状");
			return;
		} else {
			gd_zz.setBackgroundColor(Color.WHITE);
		}

		// 血压
		String str_xy = ed_xy.getText().toString();
		if (TextUtils.isEmpty(str_xy)) {
			ed_xy.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请填写血压");
			return;
		} else {
			if (!str_xy.contains("/")) {
				ed_xy.setBackgroundColor(Color.YELLOW);
				((GXYActivity) getActivity()).showTextDialog("血压数据不合理，保存失败");
				return;
			} else {
				String[] split = str_xy.split("/");
				if (!GlobalConts.isRightNumber("血压", split[0])) {
					ed_xy.setBackgroundColor(Color.YELLOW);
					((GXYActivity) getActivity()).showTextDialog("请输入正确的血压值");
					return;
				}else if (!GlobalConts.isRightNumber("血压", split[1])) {
					ed_xy.setBackgroundColor(Color.YELLOW);
					((GXYActivity) getActivity()).showTextDialog("请输入正确的血压值");
					return;
				}else{
                    gaoya = split[0];
                    diya = split[1];
                }
			}
			ed_xy.setBackgroundColor(Color.WHITE);
		}

		if(ccsffl_list.get(nice_spinner_clsffl.getSelectedIndex()).getID().equals("DM01-71_1")){

			int aa = Integer.parseInt(gaoya);
            int bb = Integer.parseInt(diya);
			Log.e(TAG,"进来了："+aa+bb);
            if(aa >= 139){
                ((GXYActivity) getActivity()).showTextDialog("请选择正确的此次随访分类");
                return;
            }
            if(bb >= 89){
                ((GXYActivity) getActivity()).showTextDialog("请选择正确的此次随访分类");
                return;
            }
            String checked = adapter_ywblfy.getChecked();
            if(checked.equals("DM01-11_2")){
                ((GXYActivity) getActivity()).showTextDialog("请选择正确的此次随访分类");
                return;
            }
        }
		// 心率
		String str_xl = ed_xl.getText().toString();
		if (TextUtils.isEmpty(str_xl)) {
			ed_xl.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请输入心率");
			return;
		} else {
			ed_xl.setBackgroundColor(Color.WHITE);
			if (!GlobalConts.isRightNumber("脉率",str_xl )) {
				ed_xl.setBackgroundColor(Color.YELLOW);
				((GXYActivity) getActivity()).showTextDialog("心率数据不合理，保存失败！");
				return;
			}
		}

		// 体重
		String str_tz = ed_tz.getText().toString();
		if (TextUtils.isEmpty(str_tz)) {
			ed_tz.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请输入体重");
			return;
		} else {
			ed_tz.setBackgroundColor(Color.WHITE);
			if (!GlobalConts.isRightNumber("体重",str_tz )) {
				ed_tz.setBackgroundColor(Color.YELLOW);
				((GXYActivity) getActivity()).showTextDialog("体重数据不合理，保存失败！");
				return;
			}
			if(null != str_tz && !str_tz.equals("")){
				int mweight = Integer.parseInt(str_tz);
				if(mweight < 10 || mweight > 300){
					((GXYActivity) getActivity()).showTextDialog("体重数据不合理，保存失败！");
					return;
				}
			}
		}

		// 身高
		String str_height = ed_height.getText().toString();
		if (TextUtils.isEmpty(str_height)) {
			ed_height.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请输入身高");
			return;
		} else {
			ed_height.setBackgroundColor(Color.WHITE);
			if (!GlobalConts.isRightNumber("身高",str_height )) {
				ed_height.setBackgroundColor(Color.YELLOW);
				((GXYActivity) getActivity()).showTextDialog("身高数据不合理，保存失败！");
				return;
			}
			if(null != str_height && !str_height.equals("")){
				int mheight = Integer.parseInt(str_height);
				if(mheight < 10 || mheight > 300){
					((GXYActivity) getActivity()).showTextDialog("身高数据不合理，保存失败！");
					return;
				}
			}
		}
		// 体质指数
		String str_tzzs = ed_tzzs.getText().toString();
		if (TextUtils.isEmpty(str_tzzs)) {
			ed_tzzs.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请输入体质指数");
			return;
		} else {
			
			if (!GlobalConts.isRightNumber("体质指数",str_tzzs )) {
				((GXYActivity) getActivity()).showTextDialog("请输入正确的身高或体重");
				return;
			}
			
		}
		
		String ed_tzzs_sfStr = ed_tzzs_sf.getText().toString();
		if (!TextUtils.isEmpty(ed_tzzs_sfStr)) {
			if (!GlobalConts.isRightNumber("体质指数",ed_tzzs_sfStr )) {
				((GXYActivity) getActivity()).showTextDialog("请输入正确的身高或体重");
				return;
			}
		}


		// 下次随访时间
		String str_xcsfsj = ed_xcsfsj.getText().toString();
		if (TextUtils.isEmpty(str_xcsfsj)) {
			ed_xcsfsj.setBackgroundColor(Color.YELLOW);
			((GXYActivity) getActivity()).showTextDialog("请选择下次随访时间");
			return;
		} else {
			ed_xcsfsj.setBackgroundColor(Color.WHITE);
		}

		followUp = new CD_HYPERTENSIONFOLLOWUP();
		saveBase();
		saveTizheng();
		saveLife();
		saveMedicine();
		followUp.setIS_UPDATE("Y");
		followUp.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
		// List<CD_HYPERTENSIONFOLLOWUP> list =
		// fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, strWhere);
		// if (list.size() > 0) {
		// for (CD_HYPERTENSIONFOLLOWUP info : list) {
		// fdbmanger.delete(info);
		// }
		// }
		followUp.setISREFERRAL(isREFERRAL);
		followUp.setREFERRALREASON(ed_zzyy.getText().toString());
		followUp.setREFERRALORG(ed_jgkb.getText().toString());
		if(!TextUtils.isEmpty(jiankangjianyi.getText())){
			followUp.setHEALTH_ASSESS(jiankangjianyi.getText().toString());
		}

		if (!TextUtils.isEmpty(str_xcsfsj)) {
			try {
				followUp.setNEXTFOLLOWUPDATE((Date) dateFormat.parse(str_xcsfsj));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		followUp.setLAST_UPDATE_DATE(new Date());
		followUp.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
		if (fromCD_HY == 1) {
			followUp.setUPDATEORG(NovaApplication.getJgbh());
			followUp.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
			fdbmanger.updata(followUp, "IDCARD='" + userInfo.getIDCARD() + "'");
		} else {
			followUp.setCREATED_BY(userInfo.getCREATED_BY());
			followUp.setCREATED_DATE(new Date());
			followUp.setCREATEORG(NovaApplication.getJgbh());
			followUp.setCREATER(NovaApplication.getJgrno());
			fdbmanger.save(followUp);
			fromCD_HY = 1;
		}
		// ((GXYActivity) getActivity()).showTextDialog("保存成功");
		Log.e(TAG, "tt" + NovaApplication.getType());
		if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType())) {
//			new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
//					.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//
//						@Override
//						public void onClick(DialogInterface dialog, int which) {
//							Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
//							intent.putExtra("type", "06");
//							intent.putExtra("szfs", szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
//							startActivity(intent);
//						}
//					}).show();
			new AlertDialog.Builder(getActivity()).setTitle("保存成功").setPositiveButton("确定", new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
						}
					}).show();
		} else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
			((GXYActivity) getActivity()).showTextDialog("保存成功");
		}
	}

	private void saveMedicine() {

		List<CD_DRUGCONDITION> drugList = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class,
				"IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "' and TYPE='1'");
		for (CD_DRUGCONDITION drug : drugList) {
			fdbmanger.delete(drug);
		}
		String medicine1 = ed_ywmc1.getText().toString();
        String yl1 = nice_spinner_yl1.getText().toString();
        int cyl1 = nice_spinner_yl1.getSelectedIndex() + 1;
        if(yl1.equals("其他")){
            cyl1 = 99;
        }
		String a = cyl1+"";
		if(cyl1 < 10){
			a = "0"+cyl1;
		}
        String cc1 = nice_spinner_cc1.getText().toString();
        int mcc1 = nice_spinner_cc1.getSelectedIndex()+1;
        if(cc1.equals("其他局部用药")){
            mcc1 = 99;
        }
        String b = mcc1+"";
        if(mcc1 < 10){
			b = "0"+mcc1;
		}
        String count1 = a+"/"+b;
		String dose1 = ed_ywmc1_mg.getText().toString();
		String medicine2 = ed_ywmc2.getText().toString();

        String yl2 = nice_spinner_yl2.getText().toString();
        int cyl2 = nice_spinner_yl2.getSelectedIndex() + 1;
        if(yl2.equals("其他")){
            cyl2 = 99;
        }
		String a2 = cyl2+"";
		if(cyl2 < 10){
			a2 = "0"+cyl2;
		}
        String cc2 = nice_spinner_cc2.getText().toString();
        int mcc2 = nice_spinner_cc2.getSelectedIndex()+1;
        if(cc2.equals("其他局部用药")){
            mcc2 = 99;
        }
		String b2 = mcc2+"";
		if(mcc2 < 10){
			b2 = "0"+mcc2;
		}
        String count2 = a2+"/"+b2;
		String dose2 = ed_ywmc2_mg.getText().toString();
		String medicine3 = ed_ywmc3.getText().toString();

        String yl3 = nice_spinner_yl3.getText().toString();
        int cyl3 = nice_spinner_yl3.getSelectedIndex() + 1;
        if(yl3.equals("其他")){
            cyl3 = 99;
        }
		String a3 = cyl3+"";
		if(cyl3 < 10){
			a3 = "0"+cyl3;
		}
        String cc3 = nice_spinner_cc3.getText().toString();
        int mcc3 = nice_spinner_cc3.getSelectedIndex()+1;
        if(cc3.equals("其他局部用药")){
            mcc3 = 99;
        }
		String b3 = mcc3+"";
		if(mcc3 < 10){
			b3 = "0"+mcc3;
		}
        String count3 = a3+"/"+b3;

		String dose3 = ed_ywmc3_mg.getText().toString();

		String otherMedicine = ed_qtyw.getText().toString();

        String yl4 = nice_spinner_yl4.getText().toString();
        int cyl4 = nice_spinner_yl4.getSelectedIndex() + 1;
        if(yl4.equals("其他")){
            cyl4 = 99;
        }
		String a4 = cyl4+"";
		if(cyl4 < 10){
			a4 = "0"+cyl4;
		}
        String cc4 = nice_spinner_cc4.getText().toString();
        int mcc4 = nice_spinner_cc4.getSelectedIndex()+1;
        if(cc4.equals("其他局部用药")){
            mcc4 = 99;
        }
		String b4 = mcc4+"";
		if(mcc4 < 10){
			b4 = "0"+mcc4;
		}
        String otherCount = a4+"/"+b4;

		String otherDose = ed_qtyw_mg.getText().toString();

		CD_DRUGCONDITION drugCondition1 = new CD_DRUGCONDITION();
		CD_DRUGCONDITION drugCondition2 = new CD_DRUGCONDITION();
		CD_DRUGCONDITION drugCondition3 = new CD_DRUGCONDITION();
		CD_DRUGCONDITION drugCondition4 = new CD_DRUGCONDITION();
		drugCondition1.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
		drugCondition2.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
		drugCondition3.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
		drugCondition4.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
		/** 类型 1高血压 2糖尿病 3精神疾病 4冠心病 5脑卒中 */
		drugCondition1.setTYPE("1");
		drugCondition2.setTYPE("1");
		drugCondition3.setTYPE("1");
		drugCondition4.setTYPE("1");
		if (!TextUtils.isEmpty(medicine1)) {
			drugCondition1.setNAME(medicine1);
			drugCondition1.setDAILYTIME(count1);
			drugCondition1.setEVERYTIMEMG(dose1);
			drugCondition1.setRES1(ywdw_list.get(nice_spinner_dw1.getSelectedIndex()).getID());
			fdbmanger.save(drugCondition1);
		}
		if (!TextUtils.isEmpty(medicine2)) {
			drugCondition2.setNAME(medicine2);
			drugCondition2.setDAILYTIME(count2);
			drugCondition2.setEVERYTIMEMG(dose2);
			drugCondition2.setRES1(ywdw_list.get(nice_spinner_dw2.getSelectedIndex()).getID());
			fdbmanger.save(drugCondition2);
		}
		if (!TextUtils.isEmpty(medicine3)) {
			drugCondition3.setNAME(medicine3);
			drugCondition3.setDAILYTIME(count3);
			drugCondition3.setEVERYTIMEMG(dose3);
			drugCondition3.setRES1(ywdw_list.get(nice_spinner_dw3.getSelectedIndex()).getID());
			fdbmanger.save(drugCondition3);
		}
		if (!TextUtils.isEmpty(otherMedicine)) {
			drugCondition4.setNAME(otherMedicine);
			drugCondition4.setDAILYTIME(otherCount);
			drugCondition4.setEVERYTIMEMG(otherDose);
			drugCondition4.setRES1(ywdw_list.get(nice_spinner_dwqt.getSelectedIndex()).getID());
			fdbmanger.save(drugCondition4);
		}

	}

	private void saveLife() {

		String fuzhuJiancha = ed_fzjc.getText().toString();

		followUp.setDAILYSMOKENUM(ed_rxyl.getText().toString());
		followUp.setDAILYDRINKNUM(ed_ryjl.getText().toString());
		followUp.setDAILYDRINKNUMTARGET(ed_xcsfmb_yj.getText().toString());
		if(!TextUtils.isEmpty(syqk_edt.getText())){
			followUp.setTOSALT(syqk_edt.getText().toString());
		}

		followUp.setDAILYSMOKENUMTARGET(ed_xcsfmb_xy.getText().toString());
		followUp.setSPORTTIMEPERWEEK(ed_yd_zq.getText().toString());
		followUp.setSPORTTIMESPERWEEKTARGET(ed_xcsfmb_yd_zq.getText().toString());
		followUp.setSPORTPERMINUTESTIMETARGET(ed_xcsfmb_yd_min.getText().toString());
		followUp.setSPORTPERMINUTETIME(ed_yd_min.getText().toString());
		followUp.setASSISTANTEXAM(fuzhuJiancha);
		followUp.setEATSALTTYPE(sy_list.get(nice_spinner_syqk.getSelectedIndex()).getID());
		followUp.setEATSALTTARGET(xcsfmb_list.get(nice_spinner_xcsfmb.getSelectedIndex()).getID());
		followUp.setPSYCHOADJUSTMENT(xltz_list.get(nice_spinner_xltz.getSelectedIndex()).getID());
		followUp.setOBEYDOCTORBEHAVIOR(zyxw_list.get(nice_spinner_zyxw.getSelectedIndex()).getID());
		followUp.setMEDICATIONCOMPLIANCE(ywycx_list.get(nice_spinner_fyycx.getSelectedIndex()).getID());
		Log.e("随诊方式---此次随访分了-------", ccsffl_list.get(nice_spinner_clsffl.getSelectedIndex()).getID());
		followUp.setFOLLOWUPTYPE(ccsffl_list.get(nice_spinner_clsffl.getSelectedIndex()).getID());
		String checked = adapter_ywblfy.getChecked();
		followUp.setADR(checked);
		followUp.setADR_EX(adapter_ywblfy.getCheckedOther());

	}

	private void saveTizheng() {
		String et_other = ed_qt.getText().toString();
		String str_xy = ed_xy.getText().toString();
		if (!TextUtils.isEmpty(str_xy)) {
			if (str_xy.contains("/")) {
				if (str_xy.split("/").length == 2) {
					followUp.setHYPERTENSION(str_xy.split("/")[0]);// 收缩压
					followUp.setHYPOTENSION(str_xy.split("/")[1]);// 舒张压
				} else {
					followUp.setHYPERTENSION("");// 收缩压
					followUp.setHYPOTENSION("");// 舒张压
				}
			} else {
				followUp.setHYPERTENSION("");// 收缩压
				followUp.setHYPOTENSION("");// 舒张压
			}
		} else {
			followUp.setHYPERTENSION("");// 收缩压
			followUp.setHYPOTENSION("");// 舒张压
		}
		// followUp.setHYPERTENSION(120);
		// followUp.setHYPOTENSION(80);
		followUp.setWEIGHT(ed_tz.getText().toString());
		followUp.setHeight(ed_height.getText().toString());
		followUp.setBMI(ed_tzzs.getText().toString());
		followUp.setHEARTRATE(ed_xl.getText().toString());
		followUp.setWEIGHTTARGET(ed_xcsfmb_tz.getText().toString());
		followUp.setBMITARGET(ed_tzzs_sf.getText().toString());
		followUp.setPHYSICALSYMPTOMOTHER(et_other);
	}

	private void saveBase() {

		try {
			String edDate = ed_date.getText().toString();
			Log.e("随访时间",edDate+"***********");
			followUp.setFOLLOWUPDATE(dateFormat.parse(edDate));
		}catch (Exception e){

		}
		followUp.setSYMPTOM(adapter_zz.getCheckedIdsStr());
		followUp.setSYMPTOMOTHER(adapter_zz.getOther());
		Log.e("tag", adapter_zz.getOther());
		followUp.setFOLLOWUPDOCTOR(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
		Log.e("随诊方式----------", szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
		if (szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID().contains("DM04-04")){
			followUp.setFOLLOWUPWAY(szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID().replace("DM04-04","DM04-15"));
		}else{
			followUp.setFOLLOWUPWAY(szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
		}
		followUp.setUPDATEORG(NovaApplication.getJgbh());
		followUp.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
	}

	@Override
	public void onClick(View v) {

		Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
		int id = v.getId();
		if (id == R.id.btn_choose_xy) {
			intent.putExtra("flag", BluetoothConstant.XUEYA_TYPENAME);
			getActivity().startActivityForResult(intent, GlobalConts.RequestXueya);
		} else if (id == R.id.btn_choose_tz) {
			intent.putExtra("flag", BluetoothConstant.TIZHONG_TYPENAME);
			getActivity().startActivityForResult(intent, GlobalConts.RequestTizhong);
		} else if (id == R.id.btn_choose_xl) {
			intent.putExtra("flag", "心率");
			getActivity().startActivityForResult(intent, GlobalConts.RequestMaiLv);
		}else {
		}
	}

	@Override
	public void setXueya(String gaoya, String diya, String mailv) {
		if (!TextUtils.isEmpty(gaoya) && !TextUtils.isEmpty(diya)) {
			ed_xy.setText(gaoya + "/" + diya);
		}

	}

	@Override
	public void setTizhong(String value) {
		ed_tz.setText(value);

	}
	@Override
	public void setMaiLv(String mailv) {
		ed_xl.setText(mailv);
	}
}
